package com.web.article.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.web.article.service.IArticleService;
import com.web.common.controller.BaseController;
import com.web.common.po.Article;

@Controller
@RequestMapping("/article")
public class ArticleController extends BaseController{
	
	public static final String ARTICLE_LIST   = "ARTICLE_LIST";
	public static final String ARTICLE_DETAIL = "ARTICLE_DETAIL";
	
	@Resource
	private IArticleService articleService;
	
	@RequestMapping(value="/list", method=RequestMethod.GET)
	public String list(HttpServletRequest request,HttpServletResponse response){
		List<Article> list = articleService.queryArticleList();
		request.getSession().setAttribute(ARTICLE_LIST, list);
		return "/article/list";
	}
	
	@RequestMapping( value="/detail", method=RequestMethod.GET)
	public String detail(HttpServletRequest request,HttpServletResponse response){
		int articleId = Integer.parseInt(request.getParameter("id"));
		Article detail = articleService.getDetail(articleId);
		request.getSession().setAttribute(ARTICLE_DETAIL, detail);
		return "/article/detail";
	}
	
	
}
